package model.entity;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import model.entity.product.Product;

@Entity
@Table(name = "OrderDetails")
public class OrderDetails {

	private OrderDetailsId id;
	private Product product;
	private Orders order;
	private int quantity;
	private int priceAtSaleTime;
	private String color;
	private String sizes;

	public OrderDetails() {
	}

	public OrderDetails(OrderDetailsId id, Product product, Orders order,
			int quantity, int priceAtSaleTime) {
		this.id = id;
		this.product = product;
		this.order = order;
		this.quantity = quantity;
		this.priceAtSaleTime = priceAtSaleTime;
	}

	public OrderDetails(OrderDetailsId id, Product product, Orders order,
			int quantity, int priceAtSaleTime, String color, String sizes) {
		this.id = id;
		this.product = product;
		this.order = order;
		this.quantity = quantity;
		this.priceAtSaleTime = priceAtSaleTime;
		this.color = color;
		this.sizes = sizes;
	}

	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "orderId", column = @Column(name = "OrderID", nullable = false)),
			@AttributeOverride(name = "productId", column = @Column(name = "ProductID", nullable = false)) })
	public OrderDetailsId getId() {
		return this.id;
	}

	public void setId(OrderDetailsId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ProductID", nullable = false, insertable = false, updatable = false)
	public Product getProduct() {
		return this.product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "OrderID", nullable = false, insertable = false, updatable = false)
	public Orders getOrder() {
		return this.order;
	}

	public void setOrder(Orders order) {
		this.order = order;
	}

	@Column(name = "Quantity", nullable = false)
	public int getQuantity() {
		return this.quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	@Column(name = "PriceAtSaleTime", nullable = false)
	public int getPriceAtSaleTime() {
		return this.priceAtSaleTime;
	}

	public void setPriceAtSaleTime(int priceAtSaleTime) {
		this.priceAtSaleTime = priceAtSaleTime;
	}

	@Column(name = "Color")
	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}
	
	@Column(name = "Sizes")
	public String getSizes() {
		return sizes;
	}

	public void setSizes(String sizes) {
		this.sizes = sizes;
	}
	
	public int totalMoney(){
		return quantity*product.getPrice();
	}
}
